/**
 * 
 */
package com.wolfware.athsweb.controllers;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.wolfware.athsweb.domain.Country;
import com.wolfware.athsweb.domain.Location;
import com.wolfware.athsweb.domain.User;
import com.wolfware.athsweb.service.BackOfficeService;

/**
 * @author Christian Strzadala
 * 
 */
public class AddUserController implements Controller {

	private BackOfficeService athsWebBackOfficeService;

	/**
	 * @param athsWebBackOfficeService
	 *            the athsWebBackOfficeService to set
	 */
	public void setAthsWebBackOfficeService(final BackOfficeService athsWebBackOfficeService) {
		this.athsWebBackOfficeService = athsWebBackOfficeService;
	}

	/**
	 * @param
	 */
	public ModelAndView handleRequest(final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		
		User user = createUser();
		athsWebBackOfficeService.registerUser(user);
		
		List<User> registeredUserList = athsWebBackOfficeService.getRegisteredUsersList();

		return new ModelAndView("registeredUsersMVC", "userList", registeredUserList);
	}

    private User createUser() {
    	User user = new User();
    	user.setDescription("Transaction User");
    	user.setFirstName("Christian");
    	user.setSurname("Strzadala");
    	user.setPassword("NO_MD5_PASS");
    	user.setDob(new Date());
    	user.setLocation(createLocation());
    	
    	return user;
    }
    
    private Location createLocation() {
    	Location location = new Location();
    	location.setId(1L);
    	location.setDescription("TEST Melbourne Desc");
    	location.setTown("MELBOURNE");
    	location.setStateCountyArea("VICTORIA");
    	location.setCountry(createCountry());
    	
    	return location;
    }
    
    private Country createCountry() {
    	Country country = new Country();
    	country.setId(1L);
    	country.setDescription("TEST Aus Desc");
    	country.setName("AUSTRALIA");
    	
    	return country;
    }
}
